from django.contrib.auth.models import User
from rest_framework import serializers
import logging
import os
import shutil

logger = logging.getLogger(__name__)


class UserSerializer(serializers.ModelSerializer):
    """
    序列化用户信息
    """
    class Meta:
        model = User
        fields = '__all__'


def jwt_response_payload_handler(token, user=None, request=None):
    """
    自定义jwt认证成功后返回的信息，包含用户信息
    """
    return {
        'token': token,
        'user': UserSerializer(user, context={'request': request}).data
    }


def svn_download(svn_address, dest_path, user='yinhb', passwd='Deny20080!'):
    """
    下载svn文件,使用前请先配置好svn_cmd路径,svn的登录用户名和密码
    """
    svn_cmd = "F:\\django\\data-service-backend\\tools\\Apache-Subversion-1.14.1\\bin\\svn.exe"
    os.system("{} co {}  --username {} --password {} {}"
              .format(svn_cmd, svn_address, user, passwd, dest_path))
